from django.views.generic import TemplateView
from django.contrib.auth.mixins import LoginRequiredMixin

class HomeView(LoginRequiredMixin, TemplateView):
    """主页视图"""
    template_name = 'battle/home.html'
    
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context['battles'] = self.request.user.participated_battles.all()[:5]  # 最近5场战斗
        context['characters'] = self.request.user.characters.filter(is_template=False)[:5]  # 最近5个角色
        return context
